function to12(time) {
  const hour = time.slice(0, 2);
  const min = time.slice(2, 4);
  if (!+hour) return `12:${min} AM`
  else if (+hour <= 12) return `${+hour}:${min} AM`;
  else return `${(+hour+12)%24}:${min} PM`;
}


let output = to12("1124");
output = to12("0030");
console.log(output);